import { CustomTableInterface } from '@/components/ProTable/interface';
import { PublicInterface } from '@/interface/public';
import { useFamilyInfoForm } from '../form/use-familyInfoForm';
import { RosterInterface } from '@/api/interface/personnel/roster/roster';

/**
 * 家庭信息
 */

export function useFamilyInfoData(proTableBox: PublicInterface.ProTableValue, drawerObj: any) {
  const { familyInfoForm, saveAddFamilyInfoForm } = useFamilyInfoForm(proTableBox);

  let familyInfoData = reactive<CustomTableInterface<RosterInterface.ResFamilyInFoListById>>({
    initParam: {
      rosterId: ''
    },
    transitionArr: [],
    // 表格配置项
    columns: [
      { prop: 'operation', label: 'operation', fixed: 'left', width: 180 },
      {
        label: '姓名',
        prop: 'name'
      },
      {
        label: '关系',
        prop: 'relation'
      },
      {
        label: '年龄',
        prop: 'age'
      },
      {
        label: '职业',
        prop: 'job'
      },
      {
        label: '联系电话',
        prop: 'phone'
      },
      {
        label: '单位或住址',
        prop: 'company',
        width: 300
      },
      {
        prop: 'remark',
        label: 'remark'
      }
    ],

    headButtonList: [
      {
        label: 'add',
        type: 'primary',
        icon: 'el-Plus',
        // permissionCode: 'roster:saveFamily',
        methods: () => {
          const params = {
            rosterId: drawerObj.value.id
          };
          formOpen(familyInfoForm, '新增家庭主要成员', params);
          setDictionaries(familyInfoForm);
        }
      }
    ],
    rowButtonList: [
      {
        label: 'edit',
        type: 'primary',
        // permissionCode: 'roster:saveFamily',
        methods: row => {
          const params = {
            rosterId: drawerObj.value.id,
            ...row
          };
          formOpen(familyInfoForm, '编辑家庭主要成员', params);
          setDictionaries(familyInfoForm);
        },
        attrs: {
          link: true
        }
      },
      {
        label: 'delete',
        type: 'danger',
        // permissionCode: 'roster:removeFamily',
        methods: row => {
          const name = `${transitionLanguages('button', 'delete')}【${row.name}】成员信息`;
          useHandleData(familyInfoDelete, { id: row.id }, name, proTableBox.value?.getTableList);
        },
        attrs: {
          link: true
        }
      }
    ]
  });

  return { familyInfoData, familyInfoForm, saveAddFamilyInfoForm };
}
